********************************************************************************
** MAIN TABLES
********************************************************************************

** TABLE 1: Summary Statistics ****
{
	use "$buildpath/output/regressions_dataset.dta", clear

	* rescale
	replace ci 			= ci/1000
	gen us_co2_rate_direct_combust = ci * ei  
	
	* label
	label var ln_val_prod	"ln Value of shipments (MUSD)"
	label var ln_val_imp 	"ln Value of imports (MUSD)"
	label var ln_val_exp 	"ln Value of exports (MUSD)"
	label var ln_val_con	"ln Value of consumption (MUSD)"
	label var net_trade 	"Net trade (M-X)/(M+S)"
	label var price_TIV 	"Domestic energy price (USD/MMBtu)"
	label var price_foreign "Foreign energy price (USD/MMBtu)"
	label var ei 			"Energy intensity (MMBtu/BUSD)"
	label var ei_2          "Energy intensity (USD/USD)"
	label var ln_wage       "ln Wage (KUSD)"
	label var price_TV 		"Domestic energy price (USD/MMBtu), using contemporaneous shares"
	label var price_TIV 	"Domestic energy price (USD/MMBtu)"
	label var price_TIV_ind "Domestic energy price, embodied (USD/MMBtu)"
	label var price_foreign "Foreign energy price (USD/MMBtu)"
	label var price_import 	"Import energy price (USD/MMBtu)"
	label var price_export 	"Export energy price (USD/MMBtu)"
	label var te_2007 		"Trade exposure (M+X)/(M+S)"	
	label var ei 			"Energy intensity (MMBtu/000 USD)"
	label var ei_tot		"Energy intensity, embodied (MMBtu/000 USD)"
	label var ei_2          "Energy intensity (USD/USD)"
	label var ci  			"Carbon intensity (tons/MMBtu)"	
	label var us_co2_rate_direct_combust "Tons per value (tons/000 USD)"
	
	* output table
	do "$producepath/code/subfunctions/Table1.do"

}


** TABLE 2 and 3: Simulation Results Tax ****
{

	* prep simulation results
	qui do "$producepath/code/subfunctions/merge_simul_results.do"


	* label variables (using tax labels)
   {
    * Top panel: production/imp/exp changing
	* (1) tax
	    label var pc_prod_t "$\% \Delta Prod $ "
		label var pc_imp_t "$\% \Delta Imp $ "
		label var pc_exp_t "$\% \Delta Exp $ "

	* Bottom Panel: leakage 
	* (1) tax
		label var abaterate_t 		"$\%$ Abatement"
		label var leakagerate_t 		"Leakage rate"
		label var leakage_agg_t 		"$\%$ Leakage"
		label var netabrate_t		 "$\%$ Net abatement"
		label var tax_rev_agg_t "Net Tax Revenue ( \\\$ B)"
		label var tr_agg_t "Median allocation factor"
		label var num_industries_t "N subsidized industries"
	}

	** TABLE 2:  ***********************
	preserve 
	keep if eivar=="ei"
	global filename "Table2A"
	global caselist t s p85h p90e
	do "$producepath/code/subfunctions/Table2.do"
	restore
	
	preserve 
	keep if eivar=="ei_tot"
	global filename "Table2B"
	global caselist t s p85h p90e
	do "$producepath/code/subfunctions/Table2.do"
	restore
	
	** TABLE 3:  ***********************
	
	* ei * 
	preserve
	keep if eivar=="ei"
	collapse (median) abaterate*
	reshape long abaterate, i(abaterate_t) j(case) string
	gen diff = abs(abaterate-abaterate_t)
	replace case = subinstr(case,"_"," ",.)
	gen scenario = word(case,2)
	gen tax = real(word(case,1))
	drop if scenario ==""
	sort scenario diff
	by scenario: keep if _n==1
	global num0 = 25
	summ tax if scenario=="s"
	global num1 `r(mean)'
	summ tax if scenario=="p85h"
	global num2 `r(mean)'
	summ tax if scenario=="p90e"
	global num3 `r(mean)'
	di $num1 "  " $num2  "   " $num3 
	restore

	preserve 
	keep if eivar=="ei"
	global filename "Table3A"
	global caselist t s p85h p90e
	qui do "$producepath/code/subfunctions/Table3.do"
	restore
	
	* ei_tot *
	preserve
	keep if eivar=="ei_tot"
	collapse (median) abaterate*
	reshape long abaterate, i(abaterate_t) j(case) string
	gen diff = abs(round(abaterate,.1)-round(abaterate_t,.1))
	replace case = subinstr(case,"_"," ",.)
	gen scenario = word(case,2)
	gen tax = real(word(case,1))
	drop if scenario ==""
	sort scenario diff
	by scenario: keep if _n==1
	global num0 = 25
	summ tax if scenario=="s"
	global num1 `r(mean)'
	summ tax if scenario=="p85h"
	global num2 `r(mean)'
	summ tax if scenario=="p90e"
	global num3 `r(mean)'
	di $num1 "  " $num2  "   " $num3 
	restore
	
	preserve 
	keep if eivar=="ei_tot"
	global filename "Table3B"
	global caselist t s p85h p90e
	qui do "$producepath/code/subfunctions/Table3.do"
	restore

}


********************************************************************************
** APPENDIX TABLES
********************************************************************************

** TABLE B.1 ****
/*
Not generated, dataset description.
*/

** TABLE C.1 ****
/*
Not generated, dataset description.
*/


** TABLE D.1 & D.2 ****
/*
Generated by Table 2 and 3 code above.
*/
